trò chơi Cannon Siege miễn phí
12.314 lượt xem;
- LevelController.cs
- Game Controller /
- Scripts /
- Assets /
- project /
1 using System.Collections;
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5 using UnityEngine.SceneManagement;
6
7 public class LevelController : MonoBehaviour {
8 public bool[] levels;
9 public Button[] levelButtons;
10
11 // Use this for initialization
12 void Start () {
13 InitilizeGameVariables ();
14 }
15
16 // Update is called once per frame
17 void Update () {
18 if(Input.GetKeyDown("Escape")){
19 SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex - 1);
20 }
21 }
22
23 void InitilizeGameVariables(){
24 if(GameController.instance != null){
25 levels = GameController.instance.levels;
26
27 for (int i = 1; i < levels.Length; i++) {
28 if (levels [i]) {
29 levelButtons [i].transform.GetChild (1).transform.gameObject.SetActive (false);
30 } else {
31 levelButtons [i].interactable = false;
32 }
33 }
34 }
35
36 }
37
38 public void LevelSelect(){
39 string level = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name;
40
41 switch(level){
42 case "Level 1":
43 if(GameController.instance != null){
44 GameController.instance.currentLevel = 1;
45 }
46 break;
47
48 case "Level 2":
49 if(GameController.instance != null){
50 GameController.instance.currentLevel = 2;
51 }
52 break;
53
54 case "Level 3":
55 if(GameController.instance != null){
56 GameController.instance.currentLevel = 3;
57 }
58 break;
59
60 case "Level 4":
61 if(GameController.instance != null){
62 GameController.instance.currentLevel = 4;
63 }
64 break;
65
66 case "Level 5":
67 if(GameController.instance != null){
68 GameController.instance.currentLevel = 5;
69 }
70 break;
71
72 case "Level 6":
73 if(GameController.instance != null){
74 GameController.instance.currentLevel = 6;
75 }
76 break;
77
78 case "Level 7":
79 if(GameController.instance != null){
80 GameController.instance.currentLevel = 7;
81 }
82 break;
83
84 case "Level 8":
85 if(GameController.instance != null){
86 GameController.instance.currentLevel = 8;
87 }
88 break;
89
90 case "Level 9":
91 if(GameController.instance != null){
92 GameController.instance.currentLevel = 9;
93 }
94 break;
95
96 case "Level 10":
97 if(GameController.instance != null){
98 GameController.instance.currentLevel = 10;
99 }
100 break;
101
102 case "Level 11":
103 if(GameController.instance != null){
104 GameController.instance.currentLevel = 11;
105 }
106 break;
107
108 case "Level 12":
109 if(GameController.instance != null){
110 GameController.instance.currentLevel = 12;
111 }
112 break;
113
114 case "Level 13":
115 if(GameController.instance != null){
116 GameController.instance.currentLevel = 13;
117 }
118 break;
119
120 case "Level 14":
121 if(GameController.instance != null){
122 GameController.instance.currentLevel = 14;
123 }
124 break;
125
126 case "Level 15":
127 if(GameController.instance != null){
128 GameController.instance.currentLevel = 15;
129 }
130 break;
131
132 }
133
134 SceneManager.LoadScene (level);
135
136 }
137 }
2 using System.Collections.Generic;
3 using UnityEngine;
4 using UnityEngine.UI;
5 using UnityEngine.SceneManagement;
6
7 public class LevelController : MonoBehaviour {
8 public bool[] levels;
9 public Button[] levelButtons;
10
11 // Use this for initialization
12 void Start () {
13 InitilizeGameVariables ();
14 }
15
16 // Update is called once per frame
17 void Update () {
18 if(Input.GetKeyDown("Escape")){
19 SceneManager.LoadScene (SceneManager.GetActiveScene ().buildIndex - 1);
20 }
21 }
22
23 void InitilizeGameVariables(){
24 if(GameController.instance != null){
25 levels = GameController.instance.levels;
26
27 for (int i = 1; i < levels.Length; i++) {
28 if (levels [i]) {
29 levelButtons [i].transform.GetChild (1).transform.gameObject.SetActive (false);
30 } else {
31 levelButtons [i].interactable = false;
32 }
33 }
34 }
35
36 }
37
38 public void LevelSelect(){
39 string level = UnityEngine.EventSystems.EventSystem.current.currentSelectedGameObject.name;
40
41 switch(level){
42 case "Level 1":
43 if(GameController.instance != null){
44 GameController.instance.currentLevel = 1;
45 }
46 break;
47
48 case "Level 2":
49 if(GameController.instance != null){
50 GameController.instance.currentLevel = 2;
51 }
52 break;
53
54 case "Level 3":
55 if(GameController.instance != null){
56 GameController.instance.currentLevel = 3;
57 }
58 break;
59
60 case "Level 4":
61 if(GameController.instance != null){
62 GameController.instance.currentLevel = 4;
63 }
64 break;
65
66 case "Level 5":
67 if(GameController.instance != null){
68 GameController.instance.currentLevel = 5;
69 }
70 break;
71
72 case "Level 6":
73 if(GameController.instance != null){
74 GameController.instance.currentLevel = 6;
75 }
76 break;
77
78 case "Level 7":
79 if(GameController.instance != null){
80 GameController.instance.currentLevel = 7;
81 }
82 break;
83
84 case "Level 8":
85 if(GameController.instance != null){
86 GameController.instance.currentLevel = 8;
87 }
88 break;
89
90 case "Level 9":
91 if(GameController.instance != null){
92 GameController.instance.currentLevel = 9;
93 }
94 break;
95
96 case "Level 10":
97 if(GameController.instance != null){
98 GameController.instance.currentLevel = 10;
99 }
100 break;
101
102 case "Level 11":
103 if(GameController.instance != null){
104 GameController.instance.currentLevel = 11;
105 }
106 break;
107
108 case "Level 12":
109 if(GameController.instance != null){
110 GameController.instance.currentLevel = 12;
111 }
112 break;
113
114 case "Level 13":
115 if(GameController.instance != null){
116 GameController.instance.currentLevel = 13;
117 }
118 break;
119
120 case "Level 14":
121 if(GameController.instance != null){
122 GameController.instance.currentLevel = 14;
123 }
124 break;
125
126 case "Level 15":
127 if(GameController.instance != null){
128 GameController.instance.currentLevel = 15;
129 }
130 break;
131
132 }
133
134 SceneManager.LoadScene (level);
135
136 }
137 }
Use this for initialization
Update is called once per frame